package com.shop2cn.iapi.shenqisettlement.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import com.ymttest.business.service.shenqi.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.OnHpSettledReq;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.shenqisettlement.service.OnHpSettledCall;
import com.shop2cn.iapi.shenqisettlement.verify.ShenqiSettlementBuildVerifyService;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.common.order.userquery.util.Utils;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.PaymentDetailPo;
import com.ymttest.database.sharding.db.sharding.model.PaymentPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DGUserWapper;

public class Ts_ShenqiRefundSettlement {

	private static OnHpSettledReq hpSettledReq = null;
	private static OnHpSettledCall hpSettledCall = new OnHpSettledCall();

	private static OrderShardingWapper wapper = new OrderShardingWapper();

	private static ShenqiSettlementBuildVerifyService shenqiSettlementBuildVerifyService = new ShenqiSettlementBuildVerifyService();

	// 盛付通手续费率
	private static String shengPayRate = "0.001";

	private static long autotest_goodsOwnerId = ShenqiUserSet.autotest_goodsOwnerId;

	private static long japanGoodsOwnerId = ShenqiUserSet.japanGoodsOwnerId;
	private static long UKGoodsOwnerId = ShenqiUserSet.UKGoodsOwnerId;
	private static long multiCurrencyGoodsOwnerId = ShenqiUserSet.multiCurrencyGoodsOwnerId;
	private static long proxyFissionGoodsOwnerId = ShenqiUserSet.proxyFissionGoodsOwnerId;
	private static long yabandGoodsOwnerId = ShenqiUserSet.yabandGoodsOwnerId;
	private static long chainStoreGoodsOwnerId = ShenqiUserSet.chainStoreGoodsOwnerId;
	private static long fundNotCollectGoodsOwnerId = ShenqiUserSet.fundNotCollectGoodsOwnerId;
	private static long platformSupplierGoodsOwnerId = ShenqiUserSet.platformSupplierGoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("代购神器结算");

		/**
		 * 将未结算的结算单置为废弃,防止结算的时间过长
		 */
		// orderSettlementWrapper.updateStatus();
	}

	@Before
	public void caseUp() {
		String accountid1;
		try {
			accountid1 = AccountCallServiceV2.getAccountId(20238699);
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
					9000000), new BigDecimal(0));

			hpSettledReq = new OnHpSettledReq();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("api/onHpSettled");

//		new MchFeeConfigWrapper().deleteAutotestData();
		wapper.activeDeadCommunicationsLink(wapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void onHpSettled(long paymentId, PaymentPo payment,
			String shengPayRate, int count) throws Exception {

		if (count < 6) {

			hpSettledReq.setTradingId(paymentId);
			hpSettledReq.setOrderAmount(payment.getRealPaidAmount());
			hpSettledReq.setSettleCurrency(payment.getSettleCurrency());
			hpSettledReq
					.setSettleAmount(payment.getRealForeignAmount() != null ? payment
							.getRealForeignAmount() : payment
							.getForeignAmount());

			if (shengPayRate != null) {

				hpSettledReq.setSettleFee(payment.getRealPaidAmount().multiply(
						new BigDecimal(shengPayRate)));
			}

			hpSettledCall.setData(hpSettledReq);
			hpSettledCall.callService();

			if (!"ok".equalsIgnoreCase(hpSettledCall.getReturnData())) {

				Thread.sleep(3000 + count * 3000);
				count++;
				this.onHpSettled(paymentId, payment, shengPayRate, count);
			}
		} else {

			throw new Exception();
		}
	}

	public void verify(long paymentId, boolean hpSettled, boolean settled)
			throws Exception {
		this.verify(paymentId, hpSettled, settled, false);
	}

	public void verify(long paymentId, boolean hpSettled, boolean settled,
			Boolean isForeignExchangeBid) throws Exception {

		this.verify(paymentId, hpSettled, settled, isForeignExchangeBid, false);
	}

	public void verify(long paymentId, boolean hpSettled, boolean settled,
			Boolean isForeignExchangeBid, Boolean isRefunded) throws Exception {

		this.verify(paymentId, hpSettled, settled, isForeignExchangeBid,
				isRefunded, false, false);
	}

	/**
	 * 
	 * @param paymentId
	 * @param hpSettled hp结算
	 * @param settled   结算单结算
	 * @param isForeignExchangeBid
	 * @param isRefunded
	 * @param isRefundedFailed
	 * @param isCollectingForOthersSettled  代收货款时，货头结算
	 * @throws Exception
	 */
	public void verify(long paymentId, boolean hpSettled, boolean settled,
			Boolean isForeignExchangeBid, Boolean isRefunded,
			Boolean isRefundedFailed, Boolean isCollectingForOthersSettled) throws Exception {

		Logger.comment(String.valueOf(isForeignExchangeBid));

		List<PaymentDetailPo> paymentDetails = wapper
				.selectPaymentDetailByPaymentId(paymentId);

		// 校验order_settlement和order_settlement_detail
		shenqiSettlementBuildVerifyService.verifySettlement(paymentDetails,
				hpSettled, settled, isForeignExchangeBid, isRefunded,
				isRefundedFailed, isCollectingForOthersSettled, hpSettledReq);
	}
	
	/**
	 * 
	 * @param paymentId
	 * @param map
	 * @throws Exception
	 */
	public void verify(long paymentId, HashMap<String, Boolean> map)
			throws Exception {

		List<PaymentDetailPo> paymentDetails = wapper
				.selectPaymentDetailByPaymentId(paymentId);

		// 校验order_settlement和order_settlement_detail
		shenqiSettlementBuildVerifyService.verifySettlement(paymentDetails,
				Utils.falseIfNull(map.get("hpSettled")),
				Utils.falseIfNull(map.get("settled")),
				Utils.falseIfNull(map.get("isForeignExchangeBid")),
				Utils.falseIfNull(map.get("isRefunded")),
				Utils.falseIfNull(map.get("isRefundedFailed")),
				Utils.falseIfNull(map.get("isCollectingForOthersSettled")),
				hpSettledReq);
	}

	@Test
	@Category(P1.class)
	@TestCase
 	public void Tc_ShenqiRefundSettlement_001() {
		Logger.start(true,
				"代购神器外币标价商品，商品标价与货头结算币种不一致, 代理订单并支付,hipopay渠道, 未调价，已接单，已结算, 退货退款完成");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) multiCurrencyGoodsOwnerId, 0,
							false, "JPY");

			String currency = productBean.getCurrency();

			productBean = DGSQBuildProxyChainCallService.createChannel(
					productBean.getSellerId(), productBean.getProductId(),
					"JPN");

			productBean = DGSQBuildProxyChainCallService.createAgent(
					productBean.getSellerId(), productBean.getProductId(),
					"CHN");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 1,
							multiCurrencyGoodsOwnerId, currency);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					currency).getExchangeRmbRate();

			SQPayGateWayCallService
					.DGSQNotifyCall(
							String.valueOf(thirdTradingId),
							totalPrice.subtract(BigDecimal.ZERO)
									.multiply(exchangeRmbRate)
									.setScale(2, BigDecimal.ROUND_HALF_DOWN)
									.toString(), userId.intValue(),
							BigDecimal.ZERO.toPlainString(), "CNY", "USD");

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			// hp结算
			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					multiCurrencyGoodsOwnerId, orderId);

			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					multiCurrencyGoodsOwnerId, paymentId, userId);

			Thread.sleep(5000);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isForeignExchangeBid", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_002() {
		Logger.start(true, "代购神器，直销商，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_003() {
		Logger.start(true, "代购神器，直销商，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			// 退货退款
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, autotest_goodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_004() {
		Logger.start(true, "代购神器，代理商，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_005() {
		Logger.start(true, "代购神器，外币支付，代理订单，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, true,
							true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithUserIdAndCurrency(productBean,
							20238699L, productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, autotest_goodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isForeignExchangeBid", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_006() {
		Logger.start(true, "代购神器，分销小店，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 2, true, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, mchId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId, (long) mchId,
					paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_007() {
		Logger.start(true, "代购神器，分销小店，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 2, true, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, mchId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, (long) mchId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_008() {
		Logger.start(true, "代购神器，代理商，盛付通支付，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, shengPayRate, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			// 整单取消，需要等取消消息
			Thread.sleep(5000);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_009() {
		Logger.start(true, "代购神器，分销小店，满减包邮，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 3, true, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithFreeFreight(productBean, true);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartProductRefundSuccess(orderId,
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), (long) mchId, paymentId, userId);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_010() {
		Logger.start(true, "代购神器，外币支付，代理订单，带各种优惠，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, true,
							true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotionAndCurrency(productBean,
							BigDecimal.TEN, autotest_goodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, autotest_goodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isForeignExchangeBid", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_011() {
		Logger.start(true, "代购神器，代理商，未调价，一个订单多个商品，已接单，已结算, 依次发起退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_012() {
		Logger.start(true, "代购神器，代理链（货头-店主），渠道商负利润订单，未结算，申请部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderNegativeProfit(productBean, BigDecimal.ZERO,
							autotest_goodsOwnerId, productBean.getCurrency(),
							null, null);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, autotest_goodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_013() {
		Logger.start(true, "代购神器，外币支付，代理订单，带各种优惠，未结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain((int) japanGoodsOwnerId, 1, false,
							true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotionAndCurrency(productBean,
							BigDecimal.TEN, japanGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("isForeignExchangeBid", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_014() {
		Logger.start(true, "代购神器，一个支付单多个订单，未调价，已接单，已结算，依次申请退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, null,
							BigDecimal.ZERO, autotest_goodsOwnerId, 2);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			// hp结算
			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					placeOrderResp.getOrderList().get(1).getOrderId());

			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_015() {
		Logger.start(true, "代购神器，代理商，未调价，已接单，已结算, 发起全部退货退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			RefundService.createFullRefundFailed(orderId, autotest_goodsOwnerId, paymentId, userId);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_016() {
		Logger.start(true, "代购神器，代理商，未调价，已接单，未结算, 全部退货退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createUKProxychain((int)UKGoodsOwnerId, 2, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.TEN,
							UKGoodsOwnerId, productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			
			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_017() {
		Logger.start(true, "代购神器，代理商，未调价，已接单，已结算, 整单退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			
			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_018() {
		Logger.start(true, "代购神器，一个支付单多个订单，未调价，已接单，已结算，依次申请退货退款，退款过程中发生错误");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, null,
							BigDecimal.ZERO, autotest_goodsOwnerId, 2);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			// hp结算
			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					placeOrderResp.getOrderList().get(1).getOrderId());

			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			
			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	// 代理裂变的退款金额可能大于结算金额，导致退款失败，用例执行不成功
	public void Tc_ShenqiRefundSettlement_019() {
		Logger.start(true, "代购神器，代理商，代理裂变（货头-店主），1个邀请人，未调价，盛付通支付，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId,
							1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.ZERO, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.delivery(proxyFissionGoodsOwnerId,
					orderId, 1234L, null);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					proxyFissionGoodsOwnerId, paymentId, userId);
			Thread.sleep(5000);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_020() {
		Logger.start(true,
				"代购神器，代理商，代理裂变（货头-店主），2个邀请人，代理订单，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId,
							2, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.ZERO, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.delivery(proxyFissionGoodsOwnerId,
					orderId, 1234L, null);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(1);

			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, proxyFissionGoodsOwnerId, paymentId, userId,
					1);

			Thread.sleep(5000);

			// 代理裂变结算
			ShenqiSettlementService.executeProxyFissionSettlementTask();

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_021() {
		Logger.start(true, "代购神器，代理商，代理裂变（货头-店主），2个邀请人，未调价，未结算, 发起整单退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId,
							2, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					proxyFissionGoodsOwnerId, paymentId, userId);

			// 整单取消，需要等取消消息
			Thread.sleep(5000);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("isRefundedFailed", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ShenqiRefundSettlement_023() {
		Logger.start(true, "代购神器，直销商，未调价，yabang支付，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) yabandGoodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, yabandGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			
			SqTradingCallService.changeDiscount(placeOrderResp
					.getOrderList().get(0).getOrderId(), placeOrderResp
					.getOrderList().get(0).getSellerId(), placeOrderResp
					.getPayableAmount().subtract(new BigDecimal("0.1"))
					.negate(), placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getFreight());
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6301");

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(yabandGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId, yabandGoodsOwnerId,
					paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ShenqiRefundSettlement_024() {
		Logger.start(true, "代购神器，直销商，未调价，连锁店模式，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) chainStoreGoodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeChainStoreOrder(productBean, chainStoreGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "501476063", "6401");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6401);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					chainStoreGoodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ShenqiRefundSettlement_025() {
		Logger.start(true, "代购神器，直销商，未调价，连锁店模式，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) chainStoreGoodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeChainStoreOrder(productBean, chainStoreGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "501476063", "6401");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6401);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			RefundService
					.createOnePartProductRefundSuccess(orderId, orderDetailPo,
							chainStoreGoodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_026() {
		Logger.start(true, "代购神器，直销商，未调价，一个订单多个商品，已接单，已结算, 发起仅退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartAmountRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId, new BigDecimal(
							"100.00"));

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_027() {
		Logger.start(true, "代购神器，直销商，未调价，一个订单多个商品，已接单，已结算, 发起仅退款, 退款过程中发生错误");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartAmountRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId, new BigDecimal(
							"100.00"));

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ShenqiRefundSettlement_028() {
		Logger.start(true, "代购神器，直销商，未调价，连锁店模式，已接单，已结算, 发起仅退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) chainStoreGoodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeChainStoreOrder(productBean, chainStoreGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "501476063", "6401");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6401);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 退货退款
			RefundService.createPartAmountRefundSuccess(orderId,
					chainStoreGoodsOwnerId, paymentId, userId, new BigDecimal(
							"100.00"));

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_029() {
		Logger.start(true, "代购神器，直销商，未调价，一个订单多个商品，已接单，已结算, 发起仅退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			// 仅退款
			RefundService.createPartAmountRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId, new BigDecimal(
							"100.00"));
			Thread.sleep(3000);
			
			// 部分退货退款
			RefundService
					.createOnePartProductRefundSuccess(orderId, orderDetailPo,
							autotest_goodsOwnerId, paymentId, userId, 1);
			Thread.sleep(3000);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_030() {
		Logger.start(true, "代购神器，代理商，使用积分，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, true);
			
			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, autotest_goodsOwnerId, 20L);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_031() {
		Logger.start(true, "代购神器，分销小店，使用积分，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 2, true, false);

			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 20L);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId, (long) mchId,
					paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_032() {
		Logger.start(true, "代购神器，代理商，使用积分，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			
			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, autotest_goodsOwnerId, 20L);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartProductRefundSuccess(orderId,
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), autotest_goodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_033() {
		Logger.start(true, "代购神器，分销小店，使用积分，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 2, true, false);

			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 20L);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartProductRefundSuccess(orderId,
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), (long)mchId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_034() {
		Logger.start(true, "代购神器，代理链（货头-店主），资金不归集，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createFundNotCollectProxychain((int) fundNotCollectGoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, fundNotCollectGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(fundNotCollectGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createPartProductRefundSuccess(orderId,
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), fundNotCollectGoodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	// 代理裂变的退款金额可能大于结算金额，导致退款失败，用例执行不成功
	public void Tc_ShenqiRefundSettlement_035() {
		Logger.start(true, "代购神器，代理商，代理裂变（货头-店主），内购模式，1个邀请人，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId,
							1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithShenqiProxyBuyOrderForProxyFission(
							productBean, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.delivery(proxyFissionGoodsOwnerId,
					orderId, 1234L, null);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					proxyFissionGoodsOwnerId, paymentId, userId);
			Thread.sleep(5000);

			// 代理裂变结算
			ShenqiSettlementService.executeProxyFissionSettlementTask();

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_036() {
		Logger.start(true,
				"代购神器，代理商，代理裂变（货头-店主），内购模式，2个邀请人，代理订单，未调价，已接单，已结算, 发起部分退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId,
							2, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithShenqiProxyBuyOrderForProxyFission(
							productBean, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.delivery(proxyFissionGoodsOwnerId,
					orderId, 1234L, null);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			// 退货退款
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, proxyFissionGoodsOwnerId, paymentId, userId,
					1);

			Thread.sleep(5000);

			// 代理裂变结算
			ShenqiSettlementService.executeProxyFissionSettlementTask();

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_037() {
		Logger.start(true, "代购神器，货头-店主-代理，独立商户代收货款，未调价，已接单，hp结算，未结算，整单退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = 501861591;

			// 创建第一个供货商商品
			String productId = DGSQBaseService.createAgentProduct(501861592,
					"", false, "CNY");

			AgentProductBean supplierProductBean_1 = new AgentProductBean();

			supplierProductBean_1.setProductId(productId);
			supplierProductBean_1.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			supplierProductBean_1.setSellerId(501861592);
			supplierProductBean_1.setCurrency("CNY");
			supplierProductBean_1.setSellerLoginId("autotest");
			supplierProductBean_1.setGoodsOwnerId((long) 501861592);

			// 将供货商商品导入到mchId
			AgentProductBean agentProductBean_1 = DGSQBuildProxyChainCallService
					.importAgentProduct(mchId, supplierProductBean_1);

			// 将商品导入到501861593
			agentProductBean_1 = DGSQBaseService.importAgentProduct(501861593,
					"", agentProductBean_1.getProductId(), (int) mchId, true);

			agentProductBean_1.setSellerId(501861593);
			agentProductBean_1.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo(501861593).get(0).getLoginId());
			agentProductBean_1.setGoodsOwnerId(supplierProductBean_1
					.getGoodsOwnerId());

			agentProductBean_1 = DGSQBaseService.importAgentProduct(501861594,
					"", agentProductBean_1.getProductId(), (int) 501861593,
					false);

			agentProductBean_1.setSellerId(501861594);
			agentProductBean_1.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo(501861594).get(0).getLoginId());
			agentProductBean_1.setCurrency("HKD");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(agentProductBean_1,
							supplierProductBean_1.getGoodsOwnerId());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			Thread.sleep(10000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					supplierProductBean_1.getGoodsOwnerId(), orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					supplierProductBean_1.getGoodsOwnerId(), paymentId, userId);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_038() {
		Logger.start(true, "代购神器，货头-店主-代理，独立商户代收货款，未调价，已接单，hp结算，已结算，依次退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = 501861591;

			// 创建第一个供货商商品
			String productId = DGSQBaseService.createAgentProduct(501861592,
					"", false, "CNY");

			AgentProductBean supplierProductBean_1 = new AgentProductBean();

			supplierProductBean_1.setProductId(productId);
			supplierProductBean_1.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			supplierProductBean_1.setSellerId(501861592);
			supplierProductBean_1.setCurrency("CNY");
			supplierProductBean_1.setSellerLoginId("autotest");
			supplierProductBean_1.setGoodsOwnerId((long) 501861592);

			// 将供货商商品导入到mchId
			AgentProductBean agentProductBean_1 = DGSQBuildProxyChainCallService
					.importAgentProduct(mchId, supplierProductBean_1);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithGoodsOwnerIdAndMultiProsInOneOrder(
							agentProductBean_1,
							supplierProductBean_1.getGoodsOwnerId());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			Thread.sleep(10000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					supplierProductBean_1.getGoodsOwnerId(), orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp, null,
					paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_040() {
		Logger.start(true, "代购神器，货头-店主-代理，独立商户代收货款，未调价，已接单，hp结算，已结算，供货商未结算，部分退款，退款过程中发生问题");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = 501861591;

			// 创建第一个供货商商品
			String productId = DGSQBaseService.createAgentProduct(501861592,
					"", false, "CNY");

			AgentProductBean supplierProductBean_1 = new AgentProductBean();

			supplierProductBean_1.setProductId(productId);
			supplierProductBean_1.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			supplierProductBean_1.setSellerId(501861592);
			supplierProductBean_1.setCurrency("CNY");
			supplierProductBean_1.setSellerLoginId("autotest");
			supplierProductBean_1.setGoodsOwnerId((long) 501861592);

			// 将供货商商品导入到mchId
			AgentProductBean agentProductBean_1 = DGSQBuildProxyChainCallService
					.importAgentProduct(mchId, supplierProductBean_1);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(agentProductBean_1,
							supplierProductBean_1.getGoodsOwnerId());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			Thread.sleep(10000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					supplierProductBean_1.getGoodsOwnerId(), orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
				
			// 退货退款
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, supplierProductBean_1.getGoodsOwnerId(), paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isCollectingForOthersSettled", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_041() {
		Logger.start(true, "代购神器，货头-店主-代理，独立商户代收货款，未调价，已接单，hp结算，已结算，供货商已结算，部分退款，退款过程中发生问题");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = 501861591;

			// 创建第一个供货商商品
			String productId = DGSQBaseService.createAgentProduct(501861592,
					"", false, "CNY");

			AgentProductBean supplierProductBean_1 = new AgentProductBean();

			supplierProductBean_1.setProductId(productId);
			supplierProductBean_1.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			supplierProductBean_1.setSellerId(501861592);
			supplierProductBean_1.setCurrency("CNY");
			supplierProductBean_1.setSellerLoginId("autotest");
			supplierProductBean_1.setGoodsOwnerId((long) 501861592);

			// 将供货商商品导入到mchId
			AgentProductBean agentProductBean_1 = DGSQBuildProxyChainCallService
					.importAgentProduct(mchId, supplierProductBean_1);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(agentProductBean_1,
							supplierProductBean_1.getGoodsOwnerId());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			Thread.sleep(10000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(
					supplierProductBean_1.getGoodsOwnerId(), orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			// 发货
			SqTradingCallService.delivery(
					supplierProductBean_1.getGoodsOwnerId(), orderId, null,
					null);
			TradingSyncService.getSyncResult(orderId);
			
			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
				
			// 退货退款
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, supplierProductBean_1.getGoodsOwnerId(), paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			map.put("isCollectingForOthersSettled", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_042() {
		Logger.start(true, "代购神器，平台供货商，未调价，已接单，已结算, 发起全部退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 2, false, "CNY");
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, platformSupplierGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					platformSupplierGoodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_043() {
		Logger.start(true, "代购神器，平台供货商，未调价，已接单，已结算, 发起部分退货退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 2, false, "CNY");
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, platformSupplierGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			// 退货退款
			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPo, platformSupplierGoodsOwnerId, paymentId, userId, 1);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_044() {
		Logger.start(true, "代购神器，平台供货商，未调价，一个订单多个商品，已接单，已结算, 依次发起退货退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 3, false, "CNY");
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_045() {
		Logger.start(true, "代购神器，平台供货商，未调价，已接单，已结算, 发起全部退货退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 3, false, "CNY");
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();
			
			RefundService.createFullRefundFailed(orderId, platformSupplierGoodsOwnerId, paymentId, userId);
			
			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);

			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_046() {
		Logger.start(true, "代购神器，平台供货商，未调价，已接单，已结算, 整单退款，退款过程中发生异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 1, false, "CNY");
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();

			// 退货退款
			RefundService.createFullRefundSuccess(orderId,
					platformSupplierGoodsOwnerId, paymentId, userId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			
			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ShenqiRefundSettlement_047() {
		Logger.start(true, "代购神器，平台供货商， 一个支付单多个订单，未调价，已接单，已结算，依次申请退货退款，退款过程中发生错误");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPlatformProxychain(
							(int) platformSupplierGoodsOwnerId, 1, false, "CNY");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, null,
							BigDecimal.ZERO, platformSupplierGoodsOwnerId, 2);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			long paymentId = wapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = wapper.selectPaymentById(paymentId);

			// hp结算
			this.onHpSettled(paymentId, payment, null, 1);

			// 接单
			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					orderId);

			SqTradingCallService.sellerAcceptOrder(platformSupplierGoodsOwnerId,
					placeOrderResp.getOrderList().get(1).getOrderId());

			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			// 退货退款
			SqTradingCallService.allOrderItemApplyRefund(placeOrderResp,
					null, paymentId);

			// 订单期望结算map
			HashMap<String, Boolean> map = new HashMap<>();

			map.put("hpSettled", true);
			map.put("settled", true);
			map.put("isRefunded", true);
			map.put("isRefundedFailed", true);
			
			this.verify(paymentId, map);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public static void main(String[] args) throws Exception {
		
		Ts_ShenqiRefundSettlement test = new Ts_ShenqiRefundSettlement();

		Long paymentId = Long.valueOf("21423580405");

		hpSettledReq = new OnHpSettledReq();

		hpSettledReq.setTradingId(paymentId);
		hpSettledReq.setSettleFee(null);

		// 订单期望结算map
		HashMap<String, Boolean> map = new HashMap<>();

		map.put("hpSettled", true);
		map.put("settled", true);
		map.put("isRefunded", true);

		test.verify(paymentId, map);
	}
}
